package current.security.dao.support;

import java.sql.Connection;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.engine.SessionImplementor;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class BaseHibernateDaoSupport extends HibernateDaoSupport {
	@Resource(name="sessionFactory")
	public void setSuperSessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}
	/**
	 * 获取session，这个session是可以自动关闭的。
	 * @return
	 */
	public Session getCurrentSession(){
		return getHibernateTemplate().getSessionFactory().getCurrentSession();
	}
	
	public Connection getConnection(){
		return ((SessionImplementor)getHibernateTemplate().getSessionFactory().getCurrentSession()).getJDBCContext().borrowConnection();
	}
}
